<%@page import="com.common.Common"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>"> 
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/maintable.css" >
<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>
<script >
$(function() {
	$("#ch_checkall,#top_ch_checkall").click(function(){
		if(this.checked){
			$("input[name=ck_id]").attr("checked","checked");
		}else{
			$("input[name=ck_id]").removeAttr("checked");
		}		
	});
	
	$("table tr").mouseover(function(){
		$(this).css("background","#D3EAEF");
		$(this).siblings().css("background","white");
	});
	
	$("#select1").val('${param.orderState}');
	
	$("#deleteAll").on('click',function (){
		var beat=false;
		$("input[name=ck_id]").each(function(){
			if(this.checked){beat=true;}
		})
		if(beat){$('form[name=form1]').submit();}
		});
	
	});
	function inputnumber(e) {
	    e.value = (e.value.replace(/[^\d]/g, ''))
	}
</script>
</head>
<body>
<div class ="div_title">
	<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>订单列表</span></div>
	<div class="div_titleoper">
		<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="goods/goods_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="javascript:void(0)" id="deleteAll"><img src="images/del.gif"/>删除</a> 
	</div>
</div>
<form action="OrderServlet.do"  id="loginForm" method="get" > 
<input type="hidden" name="flag" value="manage"> 
<table class="main_table" >
<caption >
			订单号:
			<input type="text" class="txtbox" id="orderNo" name="orderNo" value="${param.orderNo }"/>
			&ensp;
			订单日期从:
			<input type="text" class="txtbox" id="beginDate" name="beginDate" onclick="WdatePicker()" value="${param.beginDate }"/>
			到:
			<input type="text" class="txtbox" id="endDate" name="endDate" onclick="WdatePicker()" value="${param.endDate }"/> &ensp;
			订单状态:
			<%request.setAttribute("orderState", Common.EnumOrderState.values()); %>
			<select name="orderState" id="select1">
				<option value="">全部</option>
				<c:forEach var="state" items="${orderState}">
					<option value="${state.value }">${state}</option>
				</c:forEach>
			</select> 
			<button onclick="pageIndexs('1');">查询</button>
	</caption>
<tr>
	<th><input type="checkbox" id="ch_checkall" /></th>	<th>订单号</th> 	<th>付款方式</th>	<th>订单金额</th>  <th>订单状态</th> <th>邮寄方式</th><th>生成日期</th><th>发货地址</th>	<th>操作</th>
</tr>
<c:forEach var="a" items="${orderList }" varStatus="st">
	<tr>
		<td>
			<input type="checkbox" name="ck_id" value="${a.id}" /> 
		</td>
		<td>
			${a.orderNo }
		</td>
		<td>
			${a.payMethod }
		</td>
		<td>
			${a.amount }
		</td>
		<td>
			${a.orderState }
		</td>
		<td>
			${a.postMethod }
		</td>
		<td>
			<fmt:formatDate value="${a.orderDate}" type="both" pattern="yyyy-MM-dd HH:mm"/>
		</td>
		<td>
			${a.address }
		</td>
		
		<td>
			<a href="OrderServlet.do?flag=show&amp;id=${a.id}" >查看</a> 
			<c:if test="${a.orderState == '已支付' }">
				| <a href="OrderServlet.do?flag=shipments&amp;pageIndex=${page.pageIndex}&amp;id=${a.id}">发货</a>
			</c:if>
			
		</td>
	</tr>
	</c:forEach>
</table>
	<div class="div_page" >
		<div class="div_page_left"> 共有 <label>${page.rowCount }</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount }</label> 页	</div>		
	<div class="div_page_right" > 	

		<c:choose>
			<c:when test="${page.hasPre }">
				<a href="javascript:pageIndexs('1')">&nbsp;首页</a>
				<a href="javascript:pageIndexs('${page.pageIndex-1 }')">&nbsp;上一页</a>  
			</c:when>
			<c:otherwise>
				&nbsp;首页
				&nbsp;上一页
			</c:otherwise>
		</c:choose>
		
		<c:choose>
			<c:when test="${page.hasNext }">
				<a href="javascript:pageIndexs('${page.pageIndex+1 }')">&nbsp;下一页</a>
				<a href="javascript:pageIndexs('${page.pageCount }')">&nbsp;尾页</a>
			</c:when>
			<c:otherwise>
				&nbsp;下一页
				&nbsp;尾页
			</c:otherwise>
		</c:choose>

		<button onclick="pageIndexes();">转到&nbsp;&nbsp;</button>
		<input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex}" oninput="inputnumber(this)"/> &nbsp;页
		
	</div>			
	</div>
</form>
<script >
function pageIndexs(page) {
	$("#deleteAll").attr("name","");
	$("#pageIndex0").attr("name","");
	$("#pageIndex").attr("value",page);
	$('#loginForm').submit();	
}
function pageIndexes() {
	$("#deleteAll").attr("name","");
	$("#pageIndex0").attr("name","");
	$('#loginForm').submit();	
}
</script>
</body>
</html>